//
//  LoginVCViewController.m
//  gy_project
//
//  Created by 孙宏峰的MacPro on 2018/6/1.
//  Copyright © 2018年 孙宏峰的MacPro. All rights reserved.
//

#import "LoginVC.h"







//#define MobileKey @"\"mobile\""
//#define PasswordKey @"\"password\""
//#define MobileValue (self.textfield_mobile.text)
//#define PasswordValue (self.textfield_password.text)

@interface LoginVC ()
@property (weak, nonatomic) IBOutlet UIView *phoneView;
@property (weak, nonatomic) IBOutlet UIView *passwordView;
@property (weak, nonatomic) IBOutlet UIButton *login_btn;
@property (weak, nonatomic) IBOutlet UITextField *textfield_mobile;
@property (weak, nonatomic) IBOutlet UITextField *textfield_password;
@property (weak, nonatomic) IBOutlet UIImageView *check_boxImg;
/*!@brief ****   用户类型 */
@property (copy,nonatomic) NSString *type;

@end

@implementation LoginVC

#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *phoneStr = [[NSUserDefaults standardUserDefaults]valueForKey:@"rememberNum"];
    if(phoneStr.length < 1){
        self.check_boxImg.highlighted = NO;
    }else
    {
        self.check_boxImg.highlighted = YES;
        self.textfield_mobile.text = phoneStr;
    }
    
    self.phoneView.layer.cornerRadius =
    self.passwordView.layer.cornerRadius =
    self.login_btn.layer.cornerRadius = 20;
    
    self.phoneView.layer.borderColor =
    self.passwordView.layer.borderColor =
    [UIColor grayColor].CGColor;
    
    self.phoneView.layer.borderWidth =
    self.passwordView.layer.borderWidth = 1;
    
    self.phoneView.layer.masksToBounds =
    self.passwordView.layer.masksToBounds =
    self.login_btn.layer.masksToBounds =
    self.view.backgroundColor = [UIColor whiteColor];
    YES;
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDelegate
#pragma mark - customDelegate
#pragma mark - event Response
/*!@brief ****   点击登录 */
- (IBAction)loginAction:(id)sender
{
    /*!@brief ****   选中状态 */
    if(self.check_boxImg.highlighted){
        /*!@brief ****   记住手机号 */
        [[NSUserDefaults standardUserDefaults]setValue:self.textfield_mobile.text forKey:@"rememberNum"];
    }else
    {/*!@brief ****   不记住密码 */
        [[NSUserDefaults standardUserDefaults]setValue:@"" forKey:@"rememberNum"];
        
    }
    
    [self.view endEditing:NO];
    NSDictionary * pramateDict = @{
                                   @"mobile":[NSString stringWithFormat:@"%@",self.textfield_mobile.text],
                                   @"password":[NSString stringWithFormat:@"%@",self.textfield_password.text]
                                   };
    [HFNetWork postURL:Login withParameters:pramateDict withOperationCancel:NO Success:^(NSDictionary *result) {
        /*!@brief ****   登录成功 */
        
        if([result[@"code"] integerValue] == 0) {
            [[CurrentUser shared] onLoginSuccess:result];
            [self changeTabbarItem];
            [self dismissViewControllerAnimated:YES completion:nil];
            [[DYToastLaebl share] showMessage:@"登录成功" WithTime:2];
        }
    } failure:^(NSDictionary *error) {
        NSLog(@"%@",error);
        [[DYToastLaebl share] showMessage:error[@"msg"] WithTime:2];
    }];
}

- (void)changeTabbarItem
{
   
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:NO];
}
- (IBAction)clickRememberNum:(id)sender {
    self.check_boxImg.highlighted =! self.check_boxImg.highlighted;
  
}

#pragma mark - private methods


#pragma mark - getters and setters


@end
